﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using Character;
using UnityEngine;

/// <summary>数据 Manager</summary>
public static class CustomDataManager
{
	public static Dictionary<int, HeadData> Heads_Female = new Dictionary<int, HeadData>();
	public static Dictionary<int, TextAsset> faceShapes_Female = new Dictionary<int, TextAsset>();
	public static TextAsset FaceCategory_Female;
	public static Dictionary<int, PrefabData> FaceSkins_Female = new Dictionary<int, PrefabData>();
	public static Dictionary<int, PrefabData> FaceDetails_Female = new Dictionary<int, PrefabData>();
	public static Dictionary<int, PrefabData> Eyebrow_Female = new Dictionary<int, PrefabData>();
	public static Dictionary<int, PrefabData> Eyelash = new Dictionary<int, PrefabData>();
	public static Dictionary<int, PrefabData> Eye_Female = new Dictionary<int, PrefabData>();
	public static Dictionary<int, PrefabData> Eyehighlight = new Dictionary<int, PrefabData>();
	public static Dictionary<int, CombineTextureData> FaceTattoo_Female = new Dictionary<int, CombineTextureData>();
	public static Dictionary<int, CombineTextureData> Cheek = new Dictionary<int, CombineTextureData>();
	public static Dictionary<int, CombineTextureData> EyeShadow = new Dictionary<int, CombineTextureData>();
	public static Dictionary<int, CombineTextureData> Lip = new Dictionary<int, CombineTextureData>();
	public static Dictionary<int, CombineTextureData> Mole = new Dictionary<int, CombineTextureData>();
	public static TextAsset BodyShapes_Female;
	public static TextAsset BodyCategory_Female;
	public static Dictionary<int, PrefabData> BodySkins_Female = new Dictionary<int, PrefabData>();
	public static Dictionary<int, PrefabData> BodyDetails_Female = new Dictionary<int, PrefabData>();
	public static Dictionary<int, PrefabData> Nip = new Dictionary<int, PrefabData>();
	public static Dictionary<int, UnderhairData> Underhair = new Dictionary<int, UnderhairData>();
	public static Dictionary<int, CombineTextureData> Sunburn = new Dictionary<int, CombineTextureData>();
	public static Dictionary<int, CombineTextureData> BodyTattoo_Female = new Dictionary<int, CombineTextureData>();
	public static Dictionary<int, HairData> Hair_f = new Dictionary<int, HairData>();
	public static Dictionary<int, HairData> Hair_s = new Dictionary<int, HairData>();
	public static Dictionary<int, BackHairData> Hair_b = new Dictionary<int, BackHairData>();
	public static Dictionary<int, WearData>[] wears_Female = new Dictionary<int, WearData>[11];
	public static readonly int[] defWears_Female = new int[11];
	public static readonly int[] noWears_Female;

	public static Dictionary<int, HeadData> Heads_Male = new Dictionary<int, HeadData>();
	public static Dictionary<int, TextAsset> faceShapes_Male = new Dictionary<int, TextAsset>();
	public static TextAsset FaceCategory_Male;
	public static Dictionary<int, PrefabData> FaceSkins_Male = new Dictionary<int, PrefabData>();
	public static Dictionary<int, PrefabData> FaceDetails_Male = new Dictionary<int, PrefabData>();
	public static Dictionary<int, PrefabData> Eyebrow_Male = new Dictionary<int, PrefabData>();
	public static Dictionary<int, PrefabData> Eye_Male = new Dictionary<int, PrefabData>();
	public static Dictionary<int, PrefabData> Beard = new Dictionary<int, PrefabData>();
	public static Dictionary<int, CombineTextureData> FaceTattoo_Male = new Dictionary<int, CombineTextureData>();
	public static TextAsset BodyShapes_Male;
	public static TextAsset BodyCategory_Male;
	public static Dictionary<int, PrefabData> BodySkins_Male = new Dictionary<int, PrefabData>();
	public static Dictionary<int, PrefabData> BodyDetails_Male = new Dictionary<int, PrefabData>();
	public static Dictionary<int, CombineTextureData> BodyTattoo_Male = new Dictionary<int, CombineTextureData>();
	public static Dictionary<int, BackHairData> Hair_Male = new Dictionary<int, BackHairData>();
	public static Dictionary<int, WearData>[] wears_Male = new Dictionary<int, WearData>[11];
	public static readonly int[] defWears_Male = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4 };
	public static readonly int[] noWears_Male;

	public static Dictionary<int, AccessoryData>[] accessories;
	public static Shader multiplayBlendShader_2;
	public static Shader multiplayBlendShader_3;
	public static Shader multiplayBlendShader_6;
	public static Shader normalBlendShader_2;
	public static Shader normalAddShader_2;
	public static Shader hsvOffset;
	public static Shader skinBlendShader_Body;
	public static Shader skinBlendShader_Face;
	public static Shader skinBlendShader_Male;
	public static readonly int _SpecColor;
	public static readonly int _Metallic;
	public static readonly int _Smoothness;
	public static readonly int _Color_3;
	public static readonly int _SpecColor_3;
	public static readonly int _CuticleColor;
	public static readonly int _CuticleExp;
	public static readonly int _FrenelColor;
	public static readonly int _FrenelExp;
	public static readonly int _Metal;
	public static readonly int _Roughness;
	public static readonly int _Specular;
	public static readonly int _Gloss;
	public static Dictionary<string, string> WearLiquids;

	static CustomDataManager()
	{
		noWears_Female = new int[11];
		noWears_Female[0] = 101;
		noWears_Female[4] = 50;

		noWears_Male = new int[11];
		noWears_Male[0] = -1;

		accessories = new Dictionary<int, AccessoryData>[12];
		_SpecColor = Shader.PropertyToID("_SpecColor");
		_Metallic = Shader.PropertyToID("_Metallic");
		_Smoothness = Shader.PropertyToID("_Smoothness");
		_Color_3 = Shader.PropertyToID("_Color_3");
		_SpecColor_3 = Shader.PropertyToID("_SpecColor_3");
		_CuticleColor = Shader.PropertyToID("_CuticleColor");
		_CuticleExp = Shader.PropertyToID("_CuticleExp");
		_FrenelColor = Shader.PropertyToID("_FrenelColor");
		_FrenelExp = Shader.PropertyToID("_FrenelExp");
		_Metal = Shader.PropertyToID("_Metal");
		_Roughness = Shader.PropertyToID("_Roughness");
		_Specular = Shader.PropertyToID("_Specular");
		_Gloss = Shader.PropertyToID("_Gloss");
		WearLiquids = new Dictionary<string, string>();
	}
	public static void Setup()
	{
		if (Heads_Female.Count > 0) { GlobalData.Debug_LogWarning("设置完毕"); return; }

		var assetBundleController = new AssetBundleController();
		assetBundleController.OpenFromFile(GlobalData.assetBundlePath, "shape_list");
		faceShapes_Female.Add(0, assetBundleController.LoadAsset<TextAsset>("cf_anmShapeHead_01"));
		faceShapes_Female.Add(1, assetBundleController.LoadAsset<TextAsset>("cf_anmShapeHead_02"));
		faceShapes_Female.Add(2, assetBundleController.LoadAsset<TextAsset>("cf_anmShapeHead_01"));
		faceShapes_Female.Add(3, assetBundleController.LoadAsset<TextAsset>("cf_anmShapeHead_01"));
		FaceCategory_Female = assetBundleController.LoadAsset<TextAsset>("cf_customhead");
		BodyShapes_Female = assetBundleController.LoadAsset<TextAsset>("cf_anmShapeBody");
		BodyCategory_Female = assetBundleController.LoadAsset<TextAsset>("cf_custombody");
		faceShapes_Male.Add(0, assetBundleController.LoadAsset<TextAsset>("cm_anmShapeHead_01"));
		faceShapes_Male.Add(1, assetBundleController.LoadAsset<TextAsset>("cm_anmShapeHead_01"));
		FaceCategory_Male = assetBundleController.LoadAsset<TextAsset>("cm_customhead");
		BodyShapes_Male = assetBundleController.LoadAsset<TextAsset>("cm_anmShapeBody");
		BodyCategory_Male = assetBundleController.LoadAsset<TextAsset>("cm_custombody");
		assetBundleController.Close(false);

		HeadData[] array = new HeadData[]
		{
			new HeadData(0, "ヘッドA01", "FemaleHead_A1", 0, false),
			new HeadData(2, "ヘッドA02", "FemaleHead_A2", 1, false),
			new HeadData(3, "ヘッドA03", "FemaleHead_A3", 2, false),
			new HeadData(1, "ヘッドB", "FemaleHead_B", 3, false)
		};
		foreach (HeadData headData in array)
			Heads_Female.Add(headData.id, headData);

		Heads_Male.Add(0, new HeadData(0, "標準", "MaleHead_A", 0, false));
		Heads_Male.Add(1, new HeadData(1, "ほっそり", "MaleHead_B", 1, false));

		var PrefabData_Load = new CustomDataSetupLoader<PrefabData>(CustomDataSetupLoader<PrefabData>.SetupAction_Prefab);
		var HairData_Load = new CustomDataSetupLoader<HairData>(CustomDataSetupLoader<HairData>.SetupAction_Hair);
		var BackHairData_Load = new CustomDataSetupLoader<BackHairData>(CustomDataSetupLoader<BackHairData>.SetupAction_BackHair);
		var CombineTextureData_Load = new CustomDataSetupLoader<CombineTextureData>(CustomDataSetupLoader<CombineTextureData>.SetupAction_CombineTexture);
		var UnderhairData_Load = new CustomDataSetupLoader<UnderhairData>(CustomDataSetupLoader<UnderhairData>.SetupAction_UnderHair);
		var WearData_Load = new CustomDataSetupLoader<WearData>(CustomDataSetupLoader<WearData>.SetupAction_Wear);
		var AccessoryData_Load = new CustomDataSetupLoader<AccessoryData>(CustomDataSetupLoader<AccessoryData>.SetupAction_Accessory);

		PrefabData_Load.Setup_Search(FaceSkins_Female, "custommaterial/cf_m_face_*");
		PrefabData_Load.Setup_Search(FaceSkins_Male, "custommaterial/cm_m_face_*");
		PrefabData_Load.Setup_Search(FaceDetails_Female, "customtexture/cf_t_detail_f_*");
		PrefabData_Load.Setup_Search(FaceDetails_Male, "customtexture/cm_t_detail_f_*");
		PrefabData_Load.Setup_Search(Eyebrow_Female, "custommaterial/cf_m_eyebrow_*");
		PrefabData_Load.Setup_Search(Eyebrow_Male, "custommaterial/cm_m_eyebrow_*");
		PrefabData_Load.Setup_Search(Eyelash, "custommaterial/cf_m_eyelashes_*");
		PrefabData_Load.Setup_Search(Eye_Female, "custommaterial/cf_m_eye_*");
		PrefabData_Load.Setup_Search(Eye_Male, "custommaterial/cm_m_eye_*");
		PrefabData_Load.Setup_Search(Eyehighlight, "custommaterial/cf_m_eyehi_*");
		PrefabData_Load.Setup_Search(Beard, "custommaterial/cm_m_beard_*");
		CombineTextureData_Load.Setup_Search(FaceTattoo_Female, "customtexture/cf_t_tattoo_f_*");
		CombineTextureData_Load.Setup_Search(FaceTattoo_Male, "customtexture/cm_t_tattoo_f_*");
		CombineTextureData_Load.Setup_Search(Cheek, "customtexture/cf_t_cheek_*");
		CombineTextureData_Load.Setup_Search(EyeShadow, "customtexture/cf_t_eyeshadow_*");
		CombineTextureData_Load.Setup_Search(Lip, "customtexture/cf_t_lip_*");
		CombineTextureData_Load.Setup_Search(Mole, "customtexture/cf_t_mole_*");
		PrefabData_Load.Setup_Search(BodySkins_Female, "custommaterial/cf_m_body_*");
		PrefabData_Load.Setup_Search(BodySkins_Male, "custommaterial/cm_m_body_*");
		PrefabData_Load.Setup_Search(BodyDetails_Female, "customtexture/cm_t_detail_b_*");
		PrefabData_Load.Setup_Search(BodyDetails_Male, "customtexture/cm_t_detail_b_*");
		PrefabData_Load.Setup_Search(Nip, "custommaterial/cf_m_nip_*");
		UnderhairData_Load.Setup_Search(Underhair, "custommaterial/cf_m_underhair_*");
		CombineTextureData_Load.Setup_Search(Sunburn, "customtexture/cf_t_sunburn_*");
		CombineTextureData_Load.Setup_Search(Sunburn, "customtexture/cm_t_sunburn_*");
		CombineTextureData_Load.Setup_Search(BodyTattoo_Female, "customtexture/cf_t_tattoo_b_*");
		CombineTextureData_Load.Setup_Search(BodyTattoo_Male, "customtexture/cm_t_tattoo_b_*");
		BackHairData_Load.Setup_Search(Hair_b, "hair/cf_hair_b*");
		HairData_Load.Setup_Search(Hair_f, "hair/cf_hair_f*");
		HairData_Load.Setup_Search(Hair_s, "hair/cf_hair_s*");
		BackHairData_Load.Setup_Search(Hair_Male, "hair/cm_hair_*");
		string[] array3 = new string[]
		{
			"wear/cf_top_*",
			"wear/cf_bot_*",
			"wear/cf_bra_*",
			"wear/cf_shorts_*",
			"wear/cf_swim_*",
			"wear/cf_swimtop_*",
			"wear/cf_swimbot_*",
			"wear/cf_gloves_*",
			"wear/cf_panst_*",
			"wear/cf_socks_*",
			"wear/cf_shoes_*"
		};
		for (int j = 0; j < 11; j++)
		{
			wears_Female[j] = new Dictionary<int, WearData>();
			WearData_Load.Setup_Search(wears_Female[j], array3[j]);
		}
		string[] array4 = new string[]
		{
			"wear/cm_body_*",
			string.Empty,
			string.Empty,
			string.Empty,
			string.Empty,
			string.Empty,
			string.Empty,
			string.Empty,
			string.Empty,
			string.Empty,
			"wear/cm_shoes_*"
		};
		for (int k = 0; k < 11; k++)
		{
			wears_Male[k] = new Dictionary<int, WearData>();
			if (array4[k].Length != 0)
			{
				WearData_Load.Setup_Search(wears_Male[k], array4[k]);
			}
		}
		string[] array5 = new string[]
		{
			"accessory/ca_head_*",
			"accessory/ca_ear_*",
			"accessory/ca_megane_*",
			"accessory/ca_face_*",
			"accessory/ca_neck_*",
			"accessory/ca_shoulder_*",
			"accessory/ca_breast_*",
			"accessory/ca_waist_*",
			"accessory/ca_back_*",
			"accessory/ca_arm_*",
			"accessory/ca_hand_*",
			"accessory/ca_leg_*"
		};
		for (int l = 0; l < 12; l++)
		{
			accessories[l] = new Dictionary<int, AccessoryData>();
			AccessoryData_Load.Setup_Search(accessories[l], array5[l]);
		}
		string[] array6 = new string[]
		{
			"ca_head_ph00",
			"ca_ear_ph00",
			"ca_megane_ph00",
			"ca_face_ph00",
			"ca_neck_ph00",
			"ca_shoulder_ph00",
			"ca_breast_ph00",
			"ca_waist_ph00",
			"ca_back_ph00",
			"ca_arm_ph00",
			"ca_hand_ph00",
			"ca_leg_ph00"
		};
		for (int m = 0; m < 12; m++)
		{
			AccessoryData_Load.Setup_Virtual(accessories[m], array6[m]);
		}
		Setup_SearchLiquidWear(WearLiquids, "wearliquid/cf_liquid*");
		LoadIsNewData();
	}

	public static T_Data GetData_NoDataIsZeroData<T_Data>(Dictionary<int, T_Data> datas, int id) where T_Data : class
	{
		if (datas.Count == 0)
		{
			GlobalData.Debug_LogError("没有数据");
			return (T_Data)((object)null);
		}
		if (datas.ContainsKey(id))
		{
			return datas[id];
		}
		return datas.Values.First<T_Data>();
	}
	public static T_Data GetData_NoDataIsDefoData<T_Data>(Dictionary<int, T_Data> datas, int id, int def) where T_Data : class
	{
		if (datas.Count == 0)
		{
			GlobalData.Debug_LogError("没有数据");
			return (T_Data)((object)null);
		}
		if (datas.ContainsKey(id))
		{
			return datas[id];
		}
		if (datas.ContainsKey(def))
		{
			GlobalData.Debug_Log("默认数据使用");
			return datas[def];
		}
		GlobalData.Debug_LogError("连默认数据都没有");
		return datas.Values.First<T_Data>();
	}
	public static T_Data GetData_NoDataIsNull<T_Data>(Dictionary<int, T_Data> datas, int id) where T_Data : class
	{
		if (datas.ContainsKey(id))
		{
			return datas[id];
		}
		return (T_Data)((object)null);
	}
	public static bool HasData<T_Data>(Dictionary<int, T_Data> datas, int id) where T_Data : class
	{
		return datas.ContainsKey(id);
	}
	public static HeadData GetHead_Female(int id)
	{
		return GetData_NoDataIsZeroData<HeadData>(Heads_Female, id);
	}
	public static HeadData GetHead_Male(int id)
	{
		return GetData_NoDataIsZeroData<HeadData>(Heads_Male, id);
	}
	public static TextAsset GetFaceShapes_Female(int id)
	{
		return GetData_NoDataIsNull<TextAsset>(faceShapes_Female, id);
	}
	public static TextAsset GetFaceShapes_Male(int id)
	{
		return GetData_NoDataIsNull<TextAsset>(faceShapes_Male, id);
	}
	public static HairData GetHair_Female(HAIR_TYPE part, int id)
	{
		if (part == HAIR_TYPE.FRONT) return GetHair_Front(id);
		if (part == HAIR_TYPE.SIDE) return GetHair_Side(id);
		if (part == HAIR_TYPE.BACK) return GetHair_Back(id);
		return null;
	}

	public static HairData GetHair_Front(int id)
	{
		return GetData_NoDataIsNull<HairData>(Hair_f, id);
	}

	public static HairData GetHair_Side(int id)
	{
		return GetData_NoDataIsNull<HairData>(Hair_s, id);
	}

	public static BackHairData GetHair_Back(int id)
	{
		return GetData_NoDataIsNull<BackHairData>(Hair_b, id);
	}

	public static BackHairData GetHair_Male(int id)
	{
		return GetData_NoDataIsNull<BackHairData>(Hair_Male, id);
	}

	public static PrefabData GetBodySkin_Female(int id)
	{
		return GetData_NoDataIsZeroData<PrefabData>(BodySkins_Female, id);
	}

	public static PrefabData GetBodySkin_Male(int id)
	{
		return GetData_NoDataIsZeroData<PrefabData>(BodySkins_Male, id);
	}

	public static PrefabData GetBodyDetail_Female(int id)
	{
		return GetData_NoDataIsZeroData<PrefabData>(BodyDetails_Female, id);
	}

	public static PrefabData GetBodyDetail_Male(int id)
	{
		return GetData_NoDataIsZeroData<PrefabData>(BodyDetails_Male, id);
	}

	public static PrefabData GetFaceSkin_Female(int id)
	{
		return GetData_NoDataIsZeroData<PrefabData>(FaceSkins_Female, id);
	}

	public static PrefabData GetFaceSkin_Male(int id)
	{
		return GetData_NoDataIsZeroData<PrefabData>(FaceSkins_Male, id);
	}

	public static PrefabData GetFaceDetail_Female(int id)
	{
		return GetData_NoDataIsZeroData<PrefabData>(FaceDetails_Female, id);
	}

	public static PrefabData GetFaceDetail_Male(int id)
	{
		return GetData_NoDataIsZeroData<PrefabData>(FaceDetails_Male, id);
	}

	public static PrefabData GetEyebrow_Female(int id)
	{
		return GetData_NoDataIsZeroData<PrefabData>(Eyebrow_Female, id);
	}

	public static PrefabData GetEyebrow_Male(int id)
	{
		return GetData_NoDataIsZeroData<PrefabData>(Eyebrow_Male, id);
	}

	public static PrefabData GetEyelash(int id)
	{
		return GetData_NoDataIsZeroData<PrefabData>(Eyelash, id);
	}

	public static PrefabData GetEye_Female(int id)
	{
		return GetData_NoDataIsZeroData<PrefabData>(Eye_Female, id);
	}

	public static PrefabData GetEye_Male(int id)
	{
		return GetData_NoDataIsZeroData<PrefabData>(Eye_Male, id);
	}

	public static PrefabData GetEyeHighlight(int id)
	{
		return GetData_NoDataIsZeroData<PrefabData>(Eyehighlight, id);
	}

	public static PrefabData GetBeard(int id)
	{
		return GetData_NoDataIsNull<PrefabData>(Beard, id);
	}

	public static PrefabData GetNip(int id)
	{
		return GetData_NoDataIsZeroData<PrefabData>(Nip, id);
	}

	public static UnderhairData GetUnderhair(int id)
	{
		return GetData_NoDataIsNull<UnderhairData>(Underhair, id);
	}

	public static CombineTextureData GetFaceTattoo_Female(int id)
	{
		return GetData_NoDataIsNull<CombineTextureData>(FaceTattoo_Female, id);
	}

	public static CombineTextureData GetFaceTattoo_Male(int id)
	{
		return GetData_NoDataIsNull<CombineTextureData>(FaceTattoo_Male, id);
	}

	public static CombineTextureData GetCheek(int id)
	{
		return GetData_NoDataIsNull<CombineTextureData>(Cheek, id);
	}

	public static CombineTextureData GetEyeShadow(int id)
	{
		return GetData_NoDataIsNull<CombineTextureData>(EyeShadow, id);
	}

	public static CombineTextureData GetLip(int id)
	{
		return GetData_NoDataIsNull<CombineTextureData>(Lip, id);
	}

	public static CombineTextureData GetMole(int id)
	{
		return GetData_NoDataIsNull<CombineTextureData>(Mole, id);
	}

	public static CombineTextureData GetSunburn(int id)
	{
		return GetData_NoDataIsNull<CombineTextureData>(Sunburn, id);
	}

	public static CombineTextureData GetBodyTattoo_Female(int id)
	{
		return GetData_NoDataIsNull<CombineTextureData>(BodyTattoo_Female, id);
	}

	public static CombineTextureData GetBodyTattoo_Male(int id)
	{
		return GetData_NoDataIsNull<CombineTextureData>(BodyTattoo_Male, id);
	}

	public static Dictionary<int, WearData> GetWearDictionary_Female(WEAR_TYPE type)
	{
		return wears_Female[(int)type];
	}

	public static Dictionary<int, WearData> GetWearDictionary_Male(WEAR_TYPE type)
	{
		return wears_Male[(int)type];
	}

	public static WearData GetWearData(SEX sex, WEAR_TYPE type, int id)
	{
		return (sex != SEX.FEMALE) ? GetWearData_Male(type, id) : GetWearData_Female(type, id);
	}

	public static WearData GetWearData_Female(WEAR_TYPE type, int id)
	{
		if (wears_Female[(int)type] == null) return null;
		return GetData_NoDataIsZeroData<WearData>(wears_Female[(int)type], id);
	}

	public static WearData GetWearData_Male(WEAR_TYPE type, int id)
	{
		if (wears_Male[(int)type] == null) return null;
		if (type == WEAR_TYPE.TOP) return GetData_NoDataIsDefoData<WearData>(wears_Male[(int)type], id, defWears_Male[(int)type]);
		return GetData_NoDataIsNull<WearData>(wears_Male[(int)type], id);
	}

	public static bool HasWearData(SEX sex, WEAR_TYPE type, int id)
	{
		return (sex != SEX.FEMALE) ? HasWearData_Male(type, id) : HasWearData_Female(type, id);
	}

	public static bool HasWearData_Female(WEAR_TYPE type, int id)
	{
		return wears_Female[(int)type] != null && HasData<WearData>(wears_Female[(int)type], id);
	}

	public static bool HasWearData_Male(WEAR_TYPE type, int id)
	{
		return wears_Female[(int)type] != null && HasData<WearData>(wears_Male[(int)type], id);
	}

	public static int GetWearFirstData(SEX sex, WEAR_TYPE type, int id)
	{
		return (sex != SEX.FEMALE) ? GetWearFirstData_Male(type, id) : GetWearFirstData_Female(type, id);
	}

	public static int GetWearFirstData_Female(WEAR_TYPE type, int id)
	{
		if (wears_Female[(int)type] != null && wears_Female[(int)type].Count > 0)
			return wears_Female[(int)type].Values.First<WearData>().id;
		return -1;
	}

	public static int GetWearFirstData_Male(WEAR_TYPE type, int id)
	{
		if (wears_Male[(int)type] != null && wears_Male[(int)type].Count > 0)
			return wears_Male[(int)type].Values.First<WearData>().id;
		return -1;
	}

	public static Dictionary<int, AccessoryData> GetAccessoryDictionary(ACCESSORY_TYPE type)
	{
		if (type != ACCESSORY_TYPE.NONE)
			return accessories[(int)type];
		return null;
	}

	public static AccessoryData GetAcceData(ACCESSORY_TYPE type, int id)
	{
		if (type != ACCESSORY_TYPE.NONE && accessories[(int)type] != null)
			return GetData_NoDataIsNull<AccessoryData>(accessories[(int)type], id);
		return null;
	}

	public static bool HasAcceData(ACCESSORY_TYPE type, int id)
	{
		return type != ACCESSORY_TYPE.NONE && accessories[(int)type] != null && HasData<AccessoryData>(accessories[(int)type], id);
	}

	public static void Setup_SearchLiquidWear(Dictionary<string, string> datas, string search)
	{
		string text = string.Empty;
		int num = search.LastIndexOf("/");
		if (num != -1)
		{
			text = search.Substring(0, num);
			search = search.Remove(0, num + 1);
		}
		string path = GlobalData.assetBundlePath + "/" + text;
		if (Directory.Exists(path) == false) return;
		string[] files = Directory.GetFiles(path, search, SearchOption.TopDirectoryOnly);
		foreach (string path2 in files)
		{
			string extension = Path.GetExtension(path2);
			if (extension.Length == 0)
			{
				string text2 = Path.GetFileNameWithoutExtension(path2);
				if (text.Length > 0)
				{
					text2 = text + "/" + text2;
				}
				AssetBundle assetBundle = AssetBundle.LoadFromFile(GlobalData.assetBundlePath + "/" + text2);
				string[] allAssetNames = assetBundle.GetAllAssetNames();
				assetBundle.Unload(true);
				foreach (string path3 in allAssetNames)
				{
					string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path3);
					datas.Add(fileNameWithoutExtension, text2);
				}
			}
		}
	}

	public static void SaveIsNewData()
	{
		string path = Application.dataPath + "/../UserData/Save/CheckedData";
		using (FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write))
		{
			using (BinaryWriter binaryWriter = new BinaryWriter(fileStream))
			{
				SaveIsNewData(binaryWriter);
				binaryWriter.Close();
			}
			fileStream.Close();
		}
	}

	public static void SaveIsNewData(BinaryWriter writer)
	{
		SaveIsNewData<HeadData>(writer, Heads_Female);
		SaveIsNewData<HeadData>(writer, Heads_Male);
		SaveIsNewData<PrefabData>(writer, FaceSkins_Female);
		SaveIsNewData<PrefabData>(writer, FaceSkins_Male);
		SaveIsNewData<PrefabData>(writer, FaceDetails_Female);
		SaveIsNewData<PrefabData>(writer, FaceDetails_Male);
		SaveIsNewData<PrefabData>(writer, Eyebrow_Female);
		SaveIsNewData<PrefabData>(writer, Eyebrow_Male);
		SaveIsNewData<PrefabData>(writer, Eyelash);
		SaveIsNewData<PrefabData>(writer, Eye_Female);
		SaveIsNewData<PrefabData>(writer, Eye_Male);
		SaveIsNewData<PrefabData>(writer, Eyehighlight);
		SaveIsNewData<PrefabData>(writer, Beard);
		SaveIsNewData<CombineTextureData>(writer, FaceTattoo_Female);
		SaveIsNewData<CombineTextureData>(writer, FaceTattoo_Male);
		SaveIsNewData<CombineTextureData>(writer, Cheek);
		SaveIsNewData<CombineTextureData>(writer, EyeShadow);
		SaveIsNewData<CombineTextureData>(writer, Lip);
		SaveIsNewData<CombineTextureData>(writer, Mole);
		SaveIsNewData<PrefabData>(writer, BodySkins_Female);
		SaveIsNewData<PrefabData>(writer, BodySkins_Male);
		SaveIsNewData<PrefabData>(writer, BodyDetails_Female);
		SaveIsNewData<PrefabData>(writer, BodyDetails_Male);
		SaveIsNewData<PrefabData>(writer, Nip);
		SaveIsNewData<UnderhairData>(writer, Underhair);
		SaveIsNewData<CombineTextureData>(writer, Sunburn);
		SaveIsNewData<CombineTextureData>(writer, BodyTattoo_Female);
		SaveIsNewData<CombineTextureData>(writer, BodyTattoo_Male);
		SaveIsNewData<HairData>(writer, Hair_f);
		SaveIsNewData<HairData>(writer, Hair_s);
		SaveIsNewData<BackHairData>(writer, Hair_b);
		SaveIsNewData<BackHairData>(writer, Hair_Male);
		for (int i = 0; i < wears_Female.Length; i++)
		{
			SaveIsNewData<WearData>(writer, wears_Female[i]);
		}
		for (int j = 0; j < wears_Male.Length; j++)
		{
			SaveIsNewData<WearData>(writer, wears_Male[j]);
		}
	}

	public static void SaveIsNewData<T>(BinaryWriter writer, Dictionary<int, T> dic) where T : ItemDataBase
	{
		List<int> list = new List<int>();
		foreach (T t in dic.Values)
		{
			if (!t.isNew)
			{
				list.Add(t.id);
			}
		}
		writer.Write(list.Count);
		for (int i = 0; i < list.Count; i++)
		{
			writer.Write(list[i]);
		}
	}

	public static void LoadIsNewData()
	{
		string path = Application.dataPath + "/../UserData/Save/CheckedData";
		if (!File.Exists(path)) return;
		using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
		{
			using (BinaryReader binaryReader = new BinaryReader(fileStream))
			{
				LoadIsNewData(binaryReader);
				binaryReader.Close();
			}
			fileStream.Close();
		}
	}

	public static void LoadIsNewData(BinaryReader reader)
	{
		LoadIsNewData<HeadData>(reader, Heads_Female);
		LoadIsNewData<HeadData>(reader, Heads_Male);
		LoadIsNewData<PrefabData>(reader, FaceSkins_Female);
		LoadIsNewData<PrefabData>(reader, FaceSkins_Male);
		LoadIsNewData<PrefabData>(reader, FaceDetails_Female);
		LoadIsNewData<PrefabData>(reader, FaceDetails_Male);
		LoadIsNewData<PrefabData>(reader, Eyebrow_Female);
		LoadIsNewData<PrefabData>(reader, Eyebrow_Male);
		LoadIsNewData<PrefabData>(reader, Eyelash);
		LoadIsNewData<PrefabData>(reader, Eye_Female);
		LoadIsNewData<PrefabData>(reader, Eye_Male);
		LoadIsNewData<PrefabData>(reader, Eyehighlight);
		LoadIsNewData<PrefabData>(reader, Beard);
		LoadIsNewData<CombineTextureData>(reader, FaceTattoo_Female);
		LoadIsNewData<CombineTextureData>(reader, FaceTattoo_Male);
		LoadIsNewData<CombineTextureData>(reader, Cheek);
		LoadIsNewData<CombineTextureData>(reader, EyeShadow);
		LoadIsNewData<CombineTextureData>(reader, Lip);
		LoadIsNewData<CombineTextureData>(reader, Mole);
		LoadIsNewData<PrefabData>(reader, BodySkins_Female);
		LoadIsNewData<PrefabData>(reader, BodySkins_Male);
		LoadIsNewData<PrefabData>(reader, BodyDetails_Female);
		LoadIsNewData<PrefabData>(reader, BodyDetails_Male);
		LoadIsNewData<PrefabData>(reader, Nip);
		LoadIsNewData<UnderhairData>(reader, Underhair);
		LoadIsNewData<CombineTextureData>(reader, Sunburn);
		LoadIsNewData<CombineTextureData>(reader, BodyTattoo_Female);
		LoadIsNewData<CombineTextureData>(reader, BodyTattoo_Male);
		LoadIsNewData<HairData>(reader, Hair_f);
		LoadIsNewData<HairData>(reader, Hair_s);
		LoadIsNewData<BackHairData>(reader, Hair_b);
		LoadIsNewData<BackHairData>(reader, Hair_Male);
		for (int i = 0; i < wears_Female.Length; i++)
		{
			LoadIsNewData<WearData>(reader, wears_Female[i]);
		}
		for (int j = 0; j < wears_Male.Length; j++)
		{
			LoadIsNewData<WearData>(reader, wears_Male[j]);
		}
	}

	public static void LoadIsNewData<T>(BinaryReader reader, Dictionary<int, T> dic) where T : ItemDataBase
	{
		int num = reader.ReadInt32();
		for (int i = 0; i < num; i++)
		{
			int key = reader.ReadInt32();
			if (dic.ContainsKey(key))
			{
				dic[key].isNew = false;
			}
			else
			{
				GlobalData.Debug_LogWarning("以前的数据消失了？");
			}
		}
	}

	


}
